package com.fuhao.productservice.service.Impl;

import com.fuhao.productservice.model.Product;
import com.fuhao.productservice.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ProductServiceImpl implements ProductService {
    private static Map<Integer,Product> daoMap = new HashMap<>();
    private Logger logger = LoggerFactory.getLogger(getClass());




    static{
        Product p1 = new Product(1, "iphoneX", 9999, 17);
        Product p2 = new Product(2, "冰箱", 6666, 16);
        Product p3 = new Product(3, "汽车", 120000, 15);
        Product p4 = new Product(4, "洗衣机", 4432, 14);
        Product p5 = new Product(5, "电视", 6533, 13);
        Product p6 = new Product(6, "床", 1211, 11);
        Product p7 = new Product(7, "衣柜", 1111, 123);

        daoMap.put(p1.getId(), p1);
        daoMap.put(p2.getId(), p2);
        daoMap.put(p3.getId(), p3);
        daoMap.put(p4.getId(), p4);
        daoMap.put(p5.getId(), p5);
        daoMap.put(p6.getId(), p6);
        daoMap.put(p7.getId(), p7);
    }

    @Override
    public List<Product> listProduct() {
        Collection<Product> list = daoMap.values();
        return new ArrayList<>(list);
    }

    @Override
    public Product findById(Integer id) {
        logger.info("find By id");
        return daoMap.get(id);
    }
}
